package com.bckj.freshnow.goods.controller;

import com.bckj.freshnow.goods.model.GoodsRequest;
import com.bckj.freshnow.goods.model.GoodsResponse;
import com.bckj.freshnow.goods.service.GoodsService;

import org.springframework.web.bind.annotation.*;

import com.bckj.fastboot.core.page.annotation.PageQuery;
import com.github.pagehelper.PageInfo;

import lombok.RequiredArgsConstructor;
import java.util.List;


/**
 * 商品基础表(Goods)表控制层
 *
 * @author makejava
 * @since 2025-04-22 10:07:25
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("goods")
public class GoodsController {
    /**
     * 服务
     */
	private final GoodsService goodsService;
	
    /**
	 * 列表
	 *
	 * @param request req
	 * @return list
	 */
	@PageQuery
	@GetMapping("page")
	public PageInfo<GoodsResponse> page(GoodsRequest request) {
		List<GoodsResponse> data = goodsService.findAll(request);
		return new PageInfo<>(data);
	}
	
    /**
	 * 列表
	 *
	 * @param request req
	 * @return list
	 */
	@GetMapping("list")
	public List<GoodsResponse> list(GoodsRequest request) {
		return goodsService.findAll(request);
	}

	/**
	 * 增加
	 *
	 * @param request req
	 * @return boolean
	 */
	@PostMapping
	public boolean save(@RequestBody GoodsRequest request) {
		return goodsService.save(request);
	}

	/**
	 * 修改
	 *
	 * @param request req
	 * @return boolean
	 */
	@PutMapping
	public boolean update(@RequestBody GoodsRequest request) {
		return goodsService.update(request);
	}

	/**
	 * 移除
	 *
	 * @param id id
	 * @return boolean
	 */
	@DeleteMapping("{id}")
	public boolean remove(@PathVariable Long id) {
		return goodsService.remove(id);
	}

	/**
	 * 详情
	 *
	 * @param id id
	 * @return response
	 */
	@GetMapping("{id}")
	public GoodsResponse details(@PathVariable Long id) {
		return goodsService.details(id);
	}
}

